package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Classinfo;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.qo.ClassinfoQueryObject;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ClassinfoService;
import cn.wolfcode.service.EmployeeService;
import cn.wolfcode.vo.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/classinfo")
public class ClassinfoController {

    @Autowired
    private ClassinfoService classinfoService;

    @Autowired
    private EmployeeService employeeService;


    @RequiresPermissions(value = {"classinfo:list", "班级页面"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") ClassinfoQueryObject qo) {
        PageInfo<Classinfo> pageInfo = classinfoService.query(qo);
        List<Employee> employees = employeeService.selectAll();
        model.addAttribute("pageInfo", pageInfo);
        model.addAttribute("employees", employees);
        return "classinfo/list";
    }

    @RequestMapping("/delete")
    @RequiresPermissions(value = {"classinfo:delete", "班级删除"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult delete(Long id) {
        if (id != null) {
            classinfoService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"classinfo:saveOrUpdate", "班级新增/编辑"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult saveOrUpdate(Classinfo classinfo) {
        classinfoService.saveOrUpdate(classinfo);

        return new JsonResult();
    }
}
